package com.chlitina.store.modules.cash.model;

public abstract class CardPayment implements ICardPayment {
	private long paymentId;
	protected Object card;// real card in database
	private float realMoney;// real money in the database
	private float rechargeMoney;// rechargedMoney
	private float currentMoney;// current available money
	protected float money;// the money need to pay from the card
	private boolean newCard;
	// temp
	private float realCost;

	public CardPayment(Object card, long id) {
		this.card = card;
		this.paymentId = id;
	}

	public void reset() {
		currentMoney = realMoney;
		realCost = 0;
		money = 0;
		rechargeMoney = 0;
	}

	public float getMoney() {
		return money;
	}

	public void setMoney(float money) {
		this.money = money;
	}

	public abstract Object getCard();

	public void setCard(Object card) {
		this.card = card;
	}

	public float getRealMoney() {
		return realMoney;
	}

	protected void setRealMoney(float realMoney) {
		this.realMoney = realMoney;
	}

	public float getRechargeMoney() {
		return rechargeMoney;
	}

	public void setRechargeMoney(float rechargeMoney) {
		this.rechargeMoney = rechargeMoney;
	}

	/**
	 * Current available money
	 * 
	 * @return
	 */
	public float getCurrentMoney() {
		return currentMoney;
	}

	public void setCurrentMoney(float currentMoney) {
		if (currentMoney < 0) {
			throw new RuntimeException(
					"Failed to update CardPayment's current money, it can not less than 0.");
		}
		this.currentMoney = currentMoney;
	}

	public void payMoney(float realCostProduct) {
		money += realCostProduct;
		setCurrentMoney(getCurrentMoney() - realCostProduct);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Card Payment(id=" + paymentId + "): currentMoney="
				+ getCurrentMoney() + ", realMoney=" + getRealMoney());
		sb.append(", rechargeMoney=" + getRechargeMoney() + ", paidMoney="
				+ getMoney());
		return sb.toString();
	}

	@Override
	public float getRealCost() {
		return realCost;
	}

	@Override
	public void setRealCost(float realCost) {
		this.realCost = realCost;
	}

	public long getPaymentId() {
		return paymentId;
	}

	public boolean isNewCard() {
		return newCard;
	}

	public void setNewCard(boolean newCard) {
		this.newCard = newCard;
	}
}
